package l1j.server.server.model.damage.hit;

import l1j.server.server.model.Instance.L1NpcInstance;
import l1j.server.server.utils.Random;

// 用於Pc_Npc,Npc_Npc場合
public class L1OnNpcHit {
	
	private L1NpcInstance _target;
	public L1OnNpcHit(L1NpcInstance target){
		_target = target;
	}
	
	public int hitRateOnNpc(int _hitRate){
		int attackerDice = Random.nextInt(20) + 1 + _hitRate - 10;

		// 閃避率
		attackerDice -= _target.getDodge();
		attackerDice += _target.getNdodge();

		int defenderDice = 10 - _target.getAc();

		int fumble = _hitRate - 9;
		int critical = _hitRate + 10;

		if (attackerDice <= fumble) {
			_hitRate = 0;
		} else if (attackerDice >= critical) {
			_hitRate = 100;
		} else {
			if (attackerDice > defenderDice) {
				_hitRate = 100;
			} else if (attackerDice <= defenderDice) {
				_hitRate = 0;
			}
		}
		return _hitRate;
	}
}
